"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _jsxRuntime = require("react/jsx-runtime");

var _antdV = require("antd-v4");

var _react = _interopRequireWildcard(require("react"));

var addArrayKeys = function addArrayKeys(doms) {
  return doms.map(function (dom, index) {
    if (! /*#__PURE__*/_react.default.isValidElement(dom)) {
      // eslint-disable-next-line react/no-array-index-key
      return (0, _jsxRuntime.jsx)(_react.default.Fragment, {
        children: dom
      }, index);
    }

    return /*#__PURE__*/_react.default.cloneElement(dom, (0, _objectSpread2.default)({
      // eslint-disable-next-line react/no-array-index-key
      key: index
    }, dom === null || dom === void 0 ? void 0 : dom.props));
  });
};
/**
 * 一般用于放多个按钮
 *
 * @param
 */


var FieldOptions = function FieldOptions(_ref, ref) {
  var text = _ref.text,
      type = _ref.mode,
      render = _ref.render,
      fieldProps = _ref.fieldProps;

  var _useContext = (0, _react.useContext)(_antdV.ConfigProvider.ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  var className = getPrefixCls('pro-field-option');
  (0, _react.useImperativeHandle)(ref, function () {
    return {};
  });

  if (render) {
    var doms = render(text, (0, _objectSpread2.default)({
      mode: type
    }, fieldProps), (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {}));

    if (!doms || (doms === null || doms === void 0 ? void 0 : doms.length) < 1 || !Array.isArray(doms)) {
      return null;
    }

    return (0, _jsxRuntime.jsx)(_antdV.Space, {
      size: 16,
      className: className,
      children: addArrayKeys(doms)
    });
  }

  if (!text || !Array.isArray(text)) {
    if (! /*#__PURE__*/_react.default.isValidElement(text)) {
      return null;
    }

    return text;
  }

  return (0, _jsxRuntime.jsx)(_antdV.Space, {
    size: 16,
    className: className,
    children: addArrayKeys(text)
  });
};

var _default = /*#__PURE__*/_react.default.forwardRef(FieldOptions);

exports.default = _default;